import logging.config
from pynput.mouse import Controller as mController
from pynput.keyboard import Controller as kController
from pynput.keyboard import Key
import functools
import cv2 as cv
import numpy
import numpy as np
from PIL import ImageGrab, Image
import time
from cnocr import CnOcr
from datetime import datetime

# 将来简化一点代码
def sleep(s):
    # 唯一一个地方的例外
    time.sleep(s)
    return

sleep(5)
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"))
ocr = CnOcr()

# 魔兽图像的血量的绝对坐标
imTopBlood = ImageGrab.grab(
    bbox=(195, 38, 195 + 34,
          38 + 16))  # X1,Y1,X2,Y2

ptBloodLeftTopBlood = (0, 0)
ptBloodRightBottom = (40, 40)
point_color = (0, 0, 255)  # BGR
thickness = 1
lineType = 4
imgYehaibo = cv.rectangle(numpy.asarray(imTopBlood), ptBloodLeftTopBlood, ptBloodRightBottom, point_color, thickness, lineType)
cv.imwrite(r'd:/yehaibo_Blood.jpg', imgYehaibo)
# res = ocr.ocr(r'd:/yehaibo_Blood.jpg')
res = ocr.ocr(imgYehaibo)
wowStr = ''
# print(res[0][0])
for everyOne in res[0][0]:
    wowStr = wowStr + str(everyOne)
#     for everyOne in list:
#         #for everyChar in everyOne:
#         print('1')
#         print(everyOne)
            #wowStr = wowStr + str(everyChar)
print(wowStr)
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"))
